package com.old.mapper;

import com.old.dto.UserDTO;
import com.old.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("SELECT * FROM user WHERE account = #{account}")
    User findByAccount(Integer account);

    @Insert(" insert into user(account, password, name, sex,avatar,create_time,update_time,status,online) values(#{account}, #{password}, #{name}, #{sex},#{avatar},now(),now(),1,0)")
    void register(UserDTO user);

    @Select("select * from user where account = #{account} and name = #{name}")
    User findByAccountAndName(Integer account, String name);

    @Update("update user set account=#{account}, avatar=#{avatar}, password = #{password}, name = #{name}, sex = #{sex}, update_time = now() where id = #{id}")
    void save(User user);

    @Select("select * from user where id = #{userId}")
    User findByID(Integer userId);

    @Update("update user set online = 1 where id = #{id}")
    void updateOnlineStatustoTrue(Integer id);

    @Update("update user set online = 0 where id = #{id}")
    void updateOnlineStatustoFalse(int id);


    void deleteByids(List<Integer> ids);

    @Delete("delete from user where id = #{userId}")
    void deleteByUserId(Integer userId);



    @Select(" select count(*)  from user where online = 1")
    Integer  getOnline();

    //获取用户头像
    @Select("select avatar from user where id = #{userId}")
    String getUserAvatar(Integer userId);

    @Select(" select count(*)  from user where online = 0")
    Integer getOffline();


    List<User> getUserList(Integer sortBy, String searchTerms);

//    List<User> List(Integer sortBy, String searchTerms);
    @Select("select id from user")
    List<Integer> getUserIds();
}
